﻿using B.S.DataBase.MyProject.Domain;
using B.S.DataBase.MyProject.ErrorCode;
using B.S.DataBase.MyProject.Infrastructure.Interface;
using B.S.DataBase.MyRead.API.Appicant.Command.MenuCommand;
using MediatR;

namespace B.S.DataBase.MyRead.API.Appicant.CommandHandler.MenuCommandHandler
{
    public class GetOneMenuCommandHandler : IRequestHandler<GetOneMenuCommand, APIResult<MenuModel>>
    {
        private readonly IBaseRepository<MenuModel> menuRepos;

        public GetOneMenuCommandHandler(IBaseRepository<MenuModel> menuRepos)
        {
            this.menuRepos = menuRepos;
        }
        public async Task<APIResult<MenuModel>> Handle(GetOneMenuCommand request, CancellationToken cancellationToken)
        {
            APIResult<MenuModel> result=new APIResult<MenuModel>();
            var i=menuRepos.GetAll().Result.FirstOrDefault(x=>x.MenuId==request.MenuId);
            result.Code = APIEnum.操作成功;
            result.Msg= APIEnum.操作成功.ToString();
            result.data = i;
            return await Task.FromResult(result);   
        }
    }
}
